﻿--lua script
--本脚本片段实现了角色登出游戏的默认处理 

--#include "data\functions\Activity\PKChallenge\PKChallengeCommon.lua" once  --处理pk挑战退出
--#include "data\functions\player.lua" once -- 角色处理
--#include "data\functions\Activity\Dart\ApplyDartCommon.lua" once
--#include "data\functions\Guild\GuildSbkWar.lua" once --攻城战
--#include "data\functions\Guild\GuildContendWar.lua" once          --行会争夺
--#include "data\functions\Activity\Operation\operation.lua" once   --运营活动
--#include "data\functions\Boss\EquipBossCommon.lua" once           --装备boss
--#include "data\functions\Activity\DailyActivity\MulphaAdventure.lua" once                 --玛法大冒险
-------------------------------------------------------------------------------------------
--释放回购物品
EventCallDispatcher._LogoutReleaseRepurchase = function ( sysarg, args )
  local pid = Actor.getIntProperty( sysarg, PROP_ENTITY_ID )
  local rd = getActorData( sysarg, 133 )
  if ( rd == nil or table.getn(rd) <= 0 ) then
    return
  end
  table.foreachi( rd, function( i, v ) Item.releaseItemPtr( v.ptr ) end )
end
             
-------------------------------------------------------------------------------------------

-- 下线了
EventCallDispatcher.defaultHandlerPlayerLogout = function (sysarg,arg)
  local TeamId = Actor.getTeamId(sysarg)
  if TeamId ~= 0 then
	  if Fuben.getTeamFubenStatus(TeamId) == tsReady then
	  	Actor.exitTeam(sysarg)
	  end
  end
  --noviceLogoff(sysarg, arg)
  SaveData(sysarg,Actor.getIntProperty(sysarg,PROP_ENTITY_ID))
  --释放回购物品
  --EventCallDispatcher._LogoutReleaseRepurchase(sysarg,arg)
  
	local dyvar = Actor.getDyanmicVar(sysarg)
	local iFbId = dyvar and dyvar.releaseFbId or 0
	local myId = Actor.getIntProperty( sysarg, PROP_ENTITY_ID )
	if iFbId > 0 then
		--RemFromList(iFbId, myId)
		dyvar.releaseFbId = 0
	end
	if dyvar.escortMonsterHandle then
		Fuben.clearMonster(dyvar.escortMonsterHandle)
		dyvar.escortMonsterHandle = nil
	end
	--处理pk挑战数据
	if IsInPkChallengeScene(sysarg) then
		doClearPkData(sysarg)
	end

	--天书任务下线保存值
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.days then sVar.days = {} end
	local times, flushLv, surpItemId = Actor.getQuestBookInfo(sysarg, 0, 0)
	sVar.days.CoinQuestTimes = times
	sVar.BookFlushLevel = flushLv
	sVar.BookSurpItemId = surpItemId

	local guildAwardFlag, myTodayCoin = Actor.getGuildCoinAwardFlag(sysarg,0,0)
	sVar.GuildAwardFlag = guildAwardFlag
	sVar.GuildTodayCoin = myTodayCoin

	if sVar.ybstate == 1 then
		OnActorDartFailed(sysarg, StdActivityCfg[4].DartSetup.CampDartFailActorLogout);
	end

	--玩家复活时间下线保存
	local nNextReliveCd = Actor.getReliveTimeCD(sysarg,1)
	sVar.NextHpReliveCd = tonumber(nNextReliveCd)

	-- 处理玩家登出
	OnPlayerLogout(sysarg)

    --运营活动
    operationLoginOutHandler(sysarg)                

	OnGuildSiegeLogout(sysarg)                     --攻城战

    OnGuildContendLogout(sysarg)                    --行会争夺

    onEquipBossActorLogOutHandler(sysarg)           --装备boss

    OnLogoutMulphaAdventure( sysarg )           --玛法登出
end

EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeUserLogout, EventCallDispatcher.defaultHandlerPlayerLogout)
